package wifiunion.com.notice;

import android.app.Application;
import android.os.Build;
import android.os.StrictMode;

import java.util.ArrayList;
import java.util.LinkedList;

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import wifiunion.com.notice.crashprocess.CrashHandler;
import wifiunion.com.notice.entity.PushEntity;

/**
 * Created by Administrator on 2016/11/22.
 */

public class BaseApplication extends Application {



    public static BaseApplication mApplication;


    private LinkedList<BaseActivity> activities = new LinkedList<>();

//    public IntelligenceplusStatusInfo plusInfo;

    /**
     * 告警记录
     */
    private ArrayList<PushEntity> mWarnList = new ArrayList<>(4);
    /**
     * 抓拍记录
     */
    private ArrayList<PushEntity> mCaptureList = new ArrayList<>(6);


    /**
     * 全部的记录
     */
    private ArrayList<PushEntity> mAllList = new ArrayList<>(24);

    /**
     * 全部的未识别记录
     */
    private ArrayList<PushEntity> mAllWarnList = new ArrayList<>(4);

    public ArrayList<PushEntity> getCaptureList() {
        return mCaptureList;
    }

    public void setCaptureList(ArrayList<PushEntity> mCaptureList) {
        this.mCaptureList = mCaptureList;
    }

    public ArrayList<PushEntity> getWarnList() {
        return mWarnList;
    }

    public void setWarnList(ArrayList<PushEntity> mWarnList) {
        this.mWarnList = mWarnList;
    }


    public ArrayList<PushEntity> getAllList() {
        return mAllList;
    }

    public void setAllList(ArrayList<PushEntity> mAllList) {
        this.mAllList = mAllList;
    }


    public ArrayList<PushEntity> getAllWarnList() {
        return mAllWarnList;
    }

    public void setAllWarnList(ArrayList<PushEntity> mAllWarnList) {
        this.mAllWarnList = mAllWarnList;
    }


    /**
     * 切换相机时清空list
     */
    public void clearAllList() {
        mWarnList.clear();
        mCaptureList.clear();
        mAllList.clear();
        mAllWarnList.clear();
    }

    public void clearActivity() {
        for (BaseActivity ba : activities) {
            if (ba != null) {
                ba.finish();
            }
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
//        mApplication = this;
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/PINGFANG-MEDIUM.TTF")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );

        //Android 7.0 FileUriExposedException   7.0机器拍照的时候 会报FileUriExposedException的异常
        //VmPolicy方式 来实现
        //参照  http://blog.csdn.net/xiaoyu940601/article/details/54406725
        if (Build.VERSION.SDK_INT >= 24) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }

        CrashHandler.init(this);
    }


    public void addActivity(BaseActivity activity) {
        if (!activities.contains(activity)) {
            activities.add(activity);
        }
    }


    public void removeActivity(BaseActivity activity) {
        if (activities.contains(activity)) {
            activities.remove(activity);
        }
    }
}
